<?php

class Admin_Table_DirTypeEvent extends Apk_Db_Table
{
    protected $_name      = 'dir_type_event';
    protected $_primary   = 'id';
    protected $_ERROR = '';
 

    public function GetError()
    {
    	return $this->_ERROR;
    }
    
//    public function GetDataList($page = 1, $sort=null, $page_count=null)
//    {
//    	$sel = $this->getAdapter()->select()
//    		  ->from($this->_name, array('id', 'name' => 'name_'.$this->_lang))
//    		  ->joinLeft('countries', 'countries.id = cities.id_country', array('country' => 'name_'.$this->_lang))
//    		  ->joinLeft('regions', 'regions.id = cities.id_region', array('region' => 'name_'.$this->_lang));    		  
//    		  
//		if(!is_null($sort) && strlen($sort) > 0) 
//		{			
//			$sel->order($sort);			
//		}
//		else $sel->order($this->_name.'.name_'.$this->_lang);  		
//		
//
//    	return $this->setDecorator('simpleDecorator')->getPager($sel, $page, array('perPage' => $page_count));
//    } 
//    
//    public function GetDataRow($id)
//    {
//    	$sel = $this->getAdapter()->select()
//    				->from($this->_name)
//    				->where('id = ?', $id);
//
//    	return $this->setDecorator('simpleDecorator')->getList($sel)->getRow(0)->toArray();
//    }

    public function GetEventTypeList($a = null)
    {
    	$ret = array();   

		$sel = $this->getAdapter()->select()
				->from($this->name);
//				->order($this->_name.'id');
//				print_r($sel);die();
		$data = $this->getList($sel)->toArray();
		
    	if(count($data) > 0 && !is_null($a))
    	foreach($data as $k => $v)
    	  	if($v['id'] == $a) $data[$k]['__attributes']['active'] = 1;

    	return $data;
    }
        


	public function insert(array $data)
    {

        $data['name_ru'] = trim($data['name_ru']);
        if($data['name_ru'] == ''){
        	$this->_ERROR = 'Необходимо ввести Название';
        	return false;
        }

        parent::insert($data);

		return true;
    }

    public function update(array $data, $id)
    {
        $data['name_ru'] = trim($data['name_ru']);
        if($data['name_ru'] == ''){
        	$this->_ERROR = 'Необходимо ввести Название';
        	return false;
        }

		return parent::update($data, 'id = '.$id);
    }

    public function remove($items)
    {
    	foreach($items as $k => $id)
    	{	    	
	    	parent::delete('id = '.$id);
    	}    	
    	return true;
	}


    /********************
     ***  Decorators  ***
    *********************/

    public function simpleDecorator($key, $value)
    {
        switch ($key) {
            case 'public_date':
            	$result[$key]['__attributes'] = $this->timestampToArray($value);
            	break;
 			case 'contacts':
            case 'text':
            	$result[$key] = stripslashes($value);
            	break;
            default:
                $result[$key] = $value;
                break;
        }
        return $result;
    }

}
?>